package com.guchenbo.bigdata.livy;

import org.apache.livy.LivyClient;
import org.apache.livy.LivyClientBuilder;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.concurrent.ExecutionException;

/**
 * @author guchenbo
 */
public class LivyDemo {

    public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
        LivyClient client = new LivyClientBuilder().setURI(URI.create("http://vnode102:8998")).build();
        String path = "/user/guchenbo/lib/bigdata-1.0.0.jar";

        System.out.println(new File(path).getAbsolutePath());
        System.out.printf("uploading %s to the Spark Context...\n", path);
        client.uploadJar(new File(path));

        int count = 10;
        System.out.printf("running pi with %d count...\n", count);
        double pi = client.submit(new Pi(10)).get();
        System.out.println("pi is " + pi);
        client.stop(true);
    }
}
